<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.css">
    <link rel="stylesheet" type="text/css" href="../css/aui-slide.css">
    <link rel="stylesheet" type="text/css" href="../css/api.css">
    <link rel="stylesheet" href="../css/common.css">
</head>
<body class="login-bg">
    <header style="position:relative;margin-top:5%;margin-left:5%;" onclick="api.closeWin()">
      <img src="../image/left.png">
    </header>
    <div class="logo">
        <img src="../image/logo.jpg">
        <!-- <span style="font-size:30px;color:#;font-weight:bold;padding-left:5px;">芒客</span> -->
    </div>
<div class="login-box1">
    <div class="aui-content aui-margin-t-15">
        <ul class="aui-list aui-select-list">
            <li class="aui-list-item" style="width:80%;margin:auto;">
                <i class="aui-iconfont aui-icon-my"></i>
                <div class="aui-list-item-inner" style="margin-left:10px;">
                    <input id="mobile" type="text" placeholder="请输入手机号" >
                </div>
            </li>
            <li class="aui-list-item" style="width:80%;margin:auto;">
                <i class="aui-iconfont aui-icon-lock"></i>
                <div class="aui-list-item-inner" style="margin-left:10px;">
                    <input id="password" type="password" placeholder="请输入密码">
                </div>
            </li>
        </ul>
    </div>

    <p>
        <div class="aui-btn aui-btn-block aui-btn-warning" style="width:80%;margin-top:20px;margin-left: 10%;" onclick="fnLoginIn()">登录</div>
    </p>
    <div class="aui-content" style="width:80%;margin:10px auto;">
        <span onclick="Registration()">立即注册</span>
        <span class="aui-pull-right">忘记密码？</span>
    </div>
</div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    
    var token = '';

    function Registration() {
        api.openFrame({
            name: 'Registration',
            url: './Registration.html',
            rect: {
                x: 0,
                y: 0,
                w: 'auto',
                h: 'auto'
            },
            allowEdit:true
        });
    }

    function fnLoginIn() {
        var mobile = $api.byId('mobile');
        var password = $api.byId('password');
        passwordValue = password.value;
        mobileValue = mobile.value;

        var body = {
            password: passwordValue,
            mobile: mobileValue
        };
        if(mobileValue=='' ||passwordValue==''){
            alert('账号或密码不能为空');
            return false;
        }
        if(!/^1(?:3\d|4[4-9]|5[0-35-9]|6[67]|7[013-8]|8\d|9\d)\d{8}$/.test(mobileValue)){
            api.toast({
                msg:'手机号码有误',
                duration:2500,
                location:'middle'
            });
            return false;
        }
        api.toast({
            msg:'登录中……',
            duration:1500,
            location:'middle'
        });
        api.ajax({
            url: 'http://www.mk517.com/webApi/login.php',
            method: 'post',
            dataType: "json",
            "headers": {
                "Content-Type": "application/json"
            },
            data: {
                body: body
            }
        }, function(ret, err) {
            if (ret) {

              if(ret.code == -1)
              {
                alert(ret.res);
              }
              else if(ret.code== -2)
              {
                alert(ret.res);
              }

              else
              {
                api.toast({
                    msg:'登录成功',
                    duration:2000
                });
                // alert(ret.uid);
                $api.setStorage('token', ret.token);
                $api.setStorage('uid',ret.uid);
                $api.setStorage('userdata',ret);
                api.sendEvent({
                    name: 'login',
                    extra: {
                        mobile: mobileValue,
                        token: ret.token
                    }
                });
                var code=api.pageParam.code;
                // alert(code);
                if (code  == 1) {
                    api.closeWin();
                }else{
                location.href='../html/main/home.html';
                }
                
              }
              
            } else {
                alert(JSON.stringify('数据异常！'));
            }
        });
    }
</script>

</html>
